local ____lualib = require("lualib_bundle")
local __TS__New = ____lualib.__TS__New
local __TS__Class = ____lualib.__TS__Class
local __TS__ClassExtends = ____lualib.__TS__ClassExtends
local __TS__SetDescriptor = ____lualib.__TS__SetDescriptor
local __TS__SourceMapTraceBack = ____lualib.__TS__SourceMapTraceBack
__TS__SourceMapTraceBack(debug.getinfo(1).short_src, {["9"] = 2,["10"] = 2,["11"] = 4,["12"] = 4,["13"] = 5,["14"] = 5,["15"] = 7,["16"] = 9,["17"] = 9,["18"] = 9,["19"] = 9,["20"] = 12,["21"] = 9,["22"] = 14,["23"] = 12,["28"] = 56,["37"] = 63,["39"] = 69,["40"] = 70,["49"] = 77,["53"] = 24,["54"] = 24,["55"] = 24,["57"] = 25,["58"] = 25,["59"] = 25,["60"] = 25,["61"] = 25,["62"] = 25,["63"] = 26,["64"] = 27,["65"] = 27,["66"] = 27,["67"] = 27,["68"] = 28,["69"] = 24,["70"] = 35,["71"] = 36,["72"] = 36,["73"] = 36,["74"] = 37,["75"] = 38,["76"] = 36,["77"] = 36,["78"] = 35,["79"] = 46,["80"] = 47,["81"] = 47,["82"] = 47,["83"] = 48,["84"] = 47,["85"] = 47,["86"] = 46,["87"] = 84,["88"] = 85,["89"] = 84,["90"] = 92,["91"] = 93,["92"] = 92,["93"] = 100,["94"] = 101,["95"] = 100,["96"] = 109,["97"] = 110,["99"] = 111,["100"] = 112,["102"] = 113,["106"] = 116,["109"] = 119,["110"] = 109});
local ____exports = {}
local ____player = require("kernel.util.player")
local KPlayer = ____player.default
local ____AbstractData = require("kernel.interfaces.AbstractData")
local AbstractData = ____AbstractData.default
local ____cache = require("kernel.util.cache")
local Cache = ____cache.default
local cache = __TS__New(Cache)
____exports.default = __TS__Class()
local KUnit = ____exports.default
KUnit.name = "KUnit"
__TS__ClassExtends(KUnit, AbstractData)
function KUnit.prototype.____constructor(self, unit)
    AbstractData.prototype.____constructor(self)
    self.handle = unit
end
__TS__SetDescriptor(
    KUnit.prototype,
    "id",
    {get = function(self)
        return self.handle:api_get_id()
    end},
    true
)
__TS__SetDescriptor(
    KUnit.prototype,
    "name",
    {
        get = function(self)
            return self.handle:api_get_name()
        end,
        set = function(self, val)
            self.handle:api_set_name(val)
        end
    },
    true
)
__TS__SetDescriptor(
    KUnit.prototype,
    "owner",
    {get = function(self)
        return KPlayer:fromId(self.handle:api_get_role_id())
    end},
    true
)
function KUnit.create(self, player, typeId, point, angle)
    if angle == nil then
        angle = 0
    end
    local unit = gameapi.create_unit(
        typeId,
        point,
        Fix32(angle),
        player.handle
    )
    local handle = __TS__New(____exports.default, unit)
    cache:set(
        "unit:" .. tostring(handle.id),
        handle
    )
    return handle
end
function KUnit.fromId(self, id)
    return cache:get(
        "unit:" .. tostring(id),
        function()
            local unit = gameapi.get_unit_by_id(id)
            return __TS__New(____exports.default, unit)
        end
    )
end
function KUnit.fromHandle(self, unit)
    return cache:get(
        "unit:" .. tostring(unit:api_get_id()),
        function()
            return __TS__New(____exports.default, unit)
        end
    )
end
function KUnit.prototype.revive(self, point)
    self.handle:api_revive(point)
end
function KUnit.prototype.setAlarmRange(self, range)
    self.handle:api_set_unit_alarm_range(range)
end
function KUnit.prototype.setCancelAlarmRange(self, range)
    self.handle:api_set_unit_cancel_alarm_range(range)
end
function KUnit.prototype.releaseCommand(self, command, data)
    local cmd
    repeat
        local ____switch16 = command
        local ____cond16 = ____switch16 == "attackMove"
        if ____cond16 then
            cmd = gameapi.create_unit_command_attack_move(data)
            break
        end
    until true
    if not cmd then
        return
    end
    self.handle:api_release_command(cmd)
end
return ____exports
